package com.service.jkt.impl;

import com.dao.BuildingDao;
import com.dao.ClientDao;
import com.dao.RoomDao;
import com.entity.Building;
import com.entity.Client;
import com.entity.Room;
import com.service.jkt.QiTaService;
import com.util.gzp.AjaxResponse;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class QiTaServiceImpl implements QiTaService {
    @Resource
    private RoomDao roomDao;
    @Resource
    private BuildingDao buildingDao;
    @Resource
    private ClientDao clientDao;

    @Override
    public AjaxResponse findByRoomnumber(String roomnumber) {
        Room room= roomDao.findByRoomnumber(roomnumber);
        if(room!=null) {
            Building building = buildingDao.selectByPrimaryKey(room.getBuildingid());
            Map<String, Object> map = new HashMap<>();
            map.put("room", room);
            map.put("building", building);
            return AjaxResponse.success(map, "success");
        }else {
            return AjaxResponse.success(false, "fail");
        }
    }

    @Override
    public AjaxResponse findClient(Integer clientid) {
       Client cl= clientDao.selectByPrimaryKey(clientid);
       if(cl!=null) {
           return AjaxResponse.success(cl, "success");
       }else {
           return AjaxResponse.success(false, "fail");
       }
    }

    @Override
    public AjaxResponse findClientname(String ren) {
        Client cl= clientDao.findByName(ren);
        if(cl!=null) {
            return AjaxResponse.success(cl, "success");
        }else {
            return AjaxResponse.success(false, "fail");
        }
    }
}
